package sg.edu.nus.iss.umpire.service.umpire;

import javax.persistence.EntityManager;

import sg.edu.nus.iss.umpire.dao.jpa.UmpireDAOImpl;
import sg.edu.nus.iss.umpire.exception.DAOException;
import sg.edu.nus.iss.umpire.support.HttpMethod;
import sg.edu.nus.iss.umpire.support.Service;
import sg.edu.nus.iss.umpire.support.ServiceConfig;
import sg.edu.nus.iss.umpire.support.ServiceContext;
@ServiceConfig(path = "umpires/list", method = HttpMethod.GET)
public class ListUmpireService implements Service {

	@Override
	public String serve(ServiceContext ctx) throws Exception {
		ctx.getRequest().setAttribute(JSON_DATA,
				listUmpire(ctx.getEntityManager()));
		return JSON_VIEW;
	}

	private Object listUmpire(EntityManager em) throws DAOException {
		return new UmpireDAOImpl(em).loadAll();
	}
}
